Conditions | 1 |
Paths | 1 |
Total Lines | 140 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | /* |
||
8 | describe("A Column", function () { |
||
9 | |||
10 | it("must be initialized with at least name and cell", function () { |
||
11 | expect(function () { |
||
12 | new Backgrid.Column({ |
||
13 | name: "name", |
||
14 | cell: 1 |
||
15 | }); |
||
16 | }).not.toThrow(); |
||
17 | }); |
||
18 | |||
19 | it("has a label the same as name if no label given", function () { |
||
20 | var col = new Backgrid.Column({ |
||
21 | name: "name", |
||
22 | cell: 1 |
||
23 | }); |
||
24 | |||
25 | expect(col.get("label")).toBe("name"); |
||
26 | }); |
||
27 | |||
28 | it("sortValue can be a string or a function", function () { |
||
29 | var Col = Backgrid.Column.extend({ |
||
30 | mySortValue: function () {} |
||
31 | }); |
||
32 | |||
33 | var col = new Col({ |
||
34 | name: "name", |
||
35 | cell: "string", |
||
36 | sortValue: "mySortValue" |
||
37 | }); |
||
38 | |||
39 | expect(col.sortValue()).toBe(Col.prototype.mySortValue); |
||
40 | |||
41 | var mySortValue = function () {}; |
||
42 | col = new Col({ |
||
43 | name: "name", |
||
44 | cell: "string", |
||
45 | sortValue: mySortValue |
||
46 | }); |
||
47 | |||
48 | expect(col.sortValue()).toBe(mySortValue); |
||
49 | }); |
||
50 | |||
51 | it("sortable can be a string or a boolean or a function", function () { |
||
52 | var Col = Backgrid.Column.extend({ |
||
53 | mySortable: function () {} |
||
54 | }); |
||
55 | |||
56 | var col = new Col({ |
||
57 | name: "name", |
||
58 | cell: "string", |
||
59 | sortable: "mySortable" |
||
60 | }); |
||
61 | |||
62 | expect(col.sortable()).toBe(Col.prototype.mySortable); |
||
63 | |||
64 | col = new Col({ |
||
65 | name: "name", |
||
66 | cell: "string", |
||
67 | sortable: false |
||
68 | }); |
||
69 | |||
70 | expect(col.sortable()).toBe(false); |
||
71 | |||
72 | col = new Col({ |
||
73 | name: "name", |
||
74 | cell: "string", |
||
75 | sortable: function () { |
||
76 | return false; |
||
77 | } |
||
78 | }); |
||
79 | |||
80 | expect(col.sortable()).toBe(col.get("sortable")); |
||
81 | }); |
||
82 | |||
83 | it("editable can be a string or a boolean or a function", function () { |
||
84 | var Col = Backgrid.Column.extend({ |
||
85 | myEditable: function () {} |
||
86 | }); |
||
87 | |||
88 | var col = new Col({ |
||
89 | name: "name", |
||
90 | cell: "string", |
||
91 | editable: "myEditable" |
||
92 | }); |
||
93 | |||
94 | expect(col.editable()).toBe(Col.prototype.myEditable); |
||
95 | |||
96 | col = new Col({ |
||
97 | name: "name", |
||
98 | cell: "string", |
||
99 | editable: false |
||
100 | }); |
||
101 | |||
102 | expect(col.editable()).toBe(false); |
||
103 | |||
104 | col = new Col({ |
||
105 | name: "name", |
||
106 | cell: "string", |
||
107 | editable: function () { |
||
108 | return false; |
||
109 | } |
||
110 | }); |
||
111 | |||
112 | expect(col.editable()).toBe(col.get("editable")); |
||
113 | }); |
||
114 | |||
115 | it("renderable can be a string or a boolean or a function", function () { |
||
116 | var Col = Backgrid.Column.extend({ |
||
117 | myRenderable: function () {} |
||
118 | }); |
||
119 | |||
120 | var col = new Col({ |
||
121 | name: "name", |
||
122 | cell: "string", |
||
123 | renderable: "myRenderable" |
||
124 | }); |
||
125 | |||
126 | expect(col.renderable()).toBe(Col.prototype.myRenderable); |
||
127 | |||
128 | col = new Col({ |
||
129 | name: "name", |
||
130 | cell: "string", |
||
131 | renderable: false |
||
132 | }); |
||
133 | |||
134 | expect(col.renderable()).toBe(false); |
||
135 | |||
136 | col = new Col({ |
||
137 | name: "name", |
||
138 | cell: "string", |
||
139 | renderable: function () { |
||
140 | return false; |
||
141 | } |
||
142 | }); |
||
143 | |||
144 | expect(col.renderable()).toBe(col.get("renderable")); |
||
145 | }); |
||
146 | |||
147 | }); |
||
148 | |||
160 |